package com.jp.knowledge.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.activity.LoginActivity;

import org.xutils.common.util.DensityUtil;

/**
 * Created by jiayen on 16/10/12.
 * 登录dialog
 */

public class ToLoginDialog extends Dialog implements View.OnClickListener {

    private View rootView;
    private Context context;
    private TextView toLoginBtn;
    private TextView cancleBtn;
    private TextView content;
    public ToLoginDialog(Context context) {
        super(context,R.style.custom_idalgo);
        this.context=context;
    }


    public ToLoginDialog(Context context, int themeResId) {
        super(context, themeResId);
        this.context=context;
    }

    protected ToLoginDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.context=context;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rootView = getLayoutInflater().inflate(R.layout.login_dialog_layout,null);
        setContentView(rootView);
        setCanceledOnTouchOutside(false);//点空白不消失
        Window dialogWindow = this.getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width= DensityUtil.getScreenWidth()/4*3;

        lp.height=  WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
        init();
    }

    private void init(){
        content = (TextView) findViewById(R.id.content);
        cancleBtn= (TextView) findViewById(R.id.left_btn);
        toLoginBtn= (TextView) findViewById(R.id.right_btn);
        cancleBtn.setOnClickListener(this);
        toLoginBtn.setOnClickListener(this);
    }


    public void setContent(String str){
        content.setText(str);
    }
    public void setLeft(String str){
        cancleBtn.setText(str);
    }

    public void setRight(String str){
        toLoginBtn.setText(str);
    }
    @Override
    public void onClick(View view) {
        if(view.getId()==R.id.left_btn){
            dismiss();
        }else if(view.getId()==R.id.right_btn){
//            context.start
            context.startActivity(new Intent(context, LoginActivity.class));
            dismiss();
        }
    }
}
